package com.itmk.web.companyInfo.service.impl;

import com.itmk.web.companyInfo.entity.AddResume;
import com.itmk.web.companyInfo.entity.Company;
import com.itmk.web.companyInfo.entity.JobInfo;
import com.itmk.web.companyInfo.mapper.CompanyMapper;
import com.itmk.web.companyInfo.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyMapper companyMapper;
    @Override
    public Company getCompanyInfo(String uuid) {
        return companyMapper.getCompanyInfo(uuid);
    }

    @Override
    public void updateLogo(String fileName,String uuid) {
        companyMapper.updateCompanyLogo(fileName,uuid);
    }

    @Override
    public Boolean updateCompanyInfo(Company company, String uuid) {
        return companyMapper.updateCompanyInfo(company,uuid);
    }

    @Override
    public Boolean addJobInfo(JobInfo jobInfo, String uuid) {
        return companyMapper.addJobInfo(jobInfo,uuid);
    }

    @Override
    public boolean deleteJobInfo(String job_uuid, String uuid) {
        return companyMapper.deleteJobInfo(job_uuid,uuid);
    }

    @Override
    public List<JobInfo> allCompanyJob(String uuid) {
        return companyMapper.allCompanyJob(uuid);
    }

    @Override
    public JobInfo getOneJob(String jobUuid, String uuid) {
        return companyMapper.getOneJob(jobUuid,uuid);
    }

    @Override
    public List<JobInfo> getJobBySkill(String skill, String uuid) {
        return companyMapper.getJobBySkill(skill,uuid);
    }

    @Override
    public Boolean updateJobInfo(JobInfo jobInfo, String uuid) {
        return companyMapper.updateJobInfo(jobInfo,uuid);
    }

    @Override
    public boolean addResume(AddResume addResume) {
        JobInfo jobinfo = companyMapper.getResume(addResume.getJob_uuid());
        String oldResume = jobinfo.getResumes();
        String newResume;
        if(oldResume==null){
            newResume = addResume.getUserInfo_uuid();
        }else{
            newResume = oldResume+","+addResume.getUserInfo_uuid();
        }
        return companyMapper.addResume(addResume.getJob_uuid(),newResume);
    }

    @Override
    public List<String> getAllResume(String jobUuid) {
        String resume = companyMapper.getResume(jobUuid).getResumes();
        String[] resumes = resume.split(",");
        List<String> resumeList = new ArrayList<>();
        for (String s : resumes) {
            resumeList.add(s);
        }
        return resumeList;
    }
}
